iT邦幫忙

0

用 PYTHON SELENIUM 操控網頁

  • 分享至 

  • xImage
  •  

用 PYTHON SELENIUM 操控網頁 出現下述問題 徵求高手協助調適解決?

工時需耗1小時 ANYDESK遠端連線協助PRICE:TWD2,500.00

msg = f"Unable to obtain driver for {options.capabilities['browserName']} using Selenium Manager."
AttributeError: 'str' object has no attribute 'capabilities'
python-BaseException

WINDOWS10 64BYTE:PYCHARM COMMUNITY EDITION2023 程式碼 :
#• 導入相關包

from selenium import webdriver

from selenium.webdriver.common.by import By

import os
import xlrd
import xlwt
import json
import requests, json,time
from selenium.webdriver.support.wait import WebDriverWait

              ## Following section for reference during study
              ## from selenium import webdriver
              ## chrome_options = webdriver.ChromeOptions()
              ## # C:\Program Files (x86)\Common Files\Oracle\Java\javapath>
              ## chrome_options.binary_location = "C:/Program Files (x86)/Common Files/Oracle/Java/javapath/chrome.exe" 
              # 如果你想指定Chrome浏览器的路径,可以在这里添加
              ## chrome_options.add_argument("--start-maximized")
              ## # driver = webdriver.Chrome(executable_path="C:/CHROMEDRIVER/chromedriver_win32/chromedriver.exe", options=chrome_options)
              ## brguge = webdriver.Chrome(executable_path="C:/CHROMEDRIVER/chromedriver_win32/chromedriver.exe", options=chrome_options)
              ## from selenium import webdriver
              ## # C:\CHROMEDRIVER\chromedriver_win32\chromedriver
              ## 2chromedriver = "C:/CHROMEDRIVER/chromedriver_win32/chromedriver"
              ## ## os.environ["webdriver.chrome.driver"] = chromedriver
              ## # driver = webdriver.Chrome(chromedriver)
              ## brguge = webdriver.Chrome(chromedriver)
              #•	調用webdriver,進入登錄頁面
              # ChromeDriverServer = '''C:\\Users\\Chrome\\chromedriver.exe'''
              # ChromeDriverServer = '''C:\\Users\\Chrome\\chromedriver.exe'''
              ## browser = webdriver.Chrome()
              ## browser.get('http://www.baidu.com/')

brguge = webdriver.Chrome()
url='https://www.baidu.com/'
myurl='' #跳轉後的頁面
#os.environ["webdriver.chrome.driver"] = ChromeDriverServer
#brguge = webdriver.Chrome(executable_path=ChromeDriverServer)

brguge.get(url) # 發送get請求
##brguge.find_element_by_id('username').send_keys('robXXXXpe') # 輸入用戶名for old version
##brguge.find_element_by_id('password').send_keys('71XXXXXXu') # 輸入密碼 for old version
brguge.find_element(By.ID, 'username').send_keys('robXXXXpe') # 輸入用戶名 for new version
brguge.find_element(By.ID, 'password').send_keys('71XXXXXXu') # 輸入密碼 for new version

time.sleep(0.5)
brguge.find_element_by_class_name('loginBtn').click() # 確認
print(brguge.current_url) # 輸出搜索的路徑
brguge.get(myurl)

              #•	讀取excel
              # xlsfile表示絕對路徑,如

xlsfile = r'E:\PYTHON LESSON\TEST DATA.xlsx'
def read(xlsfile):
book = xlrd.open_workbook(xlsfile)#得到Excel文件的book對象,實例化對象
sheet0 = book.sheet_by_index(0) # 通過sheet索引獲得sheet對象
sheet_name = book.sheet_names()[0]# 獲得指定索引的sheet表名字
sheet1 = book.sheet_by_name(sheet_name)# 通過sheet名字來獲取,當然如果知道sheet名字就可以直接指定
nrows = sheet0.nrows # 獲取行總數
ncols = sheet0.ncols #獲取列總數

for i in range(nrows):
    list.append([])
    for j in range(ncols):
        # print(sheet0.cell_value(i, j))
        list[i].append(str(sheet0.cell_value(i,j)))
print(list)
return list
              #•	從list將內容寫入網頁
gz=brguge.find_elements_by_name('gz')
for i in range(0, rows):
    gz[i].clear()
    gz[i].send_keys(list[i+2][0])  # 輸入
brguge.find_element_by_id('s1_ok').click()# 確認

B. RGDS.,
ROBERT CHEN


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言